
<h2 style='text-align:center'>开通城市管理</h2>

<div style='text-indent:30px;margin:20px auto'>
	开通状态:
	<select id="MainCounty_CityOpenStat">
		<option value="1">全部城市</option>
		<option value="2">已开通城市</option>
		<option value="3">未开通城市</option>
	</select>　

	<button id='openCitySameUpyun'>同步upyun</button>
</div>

<div style=''>
	<div id='LoginCityArea' style='text-align:center'>
		<select id="MainCounty_Province"></select>
		<select id="MainCounty_City"></select>
		<select id="MainCounty_County"></select>
	</div>

	<div style='margin:20px auto;display:flex'>
		<div style='width:100px;text-align:right'>库　址：</div>
		<div style='flex:1'>
			<input id='MainCounty_DbHost' style='width:230px' />
		</div>
	</div>
	<div style='margin:20px auto;display:flex'>
		<div style='width:100px;text-align:right'>库　名：</div>
		<div style='flex:1'>
			<input id='MainCounty_DbName' style='width:230px' />
		</div>
	</div>
	<!--div style='margin:20px auto;display:flex'>
		<div style='width:100px;text-align:right'>验证码：</div>
		<div style='flex:1'>
			<input id='MainCounty_VCode' style='width:70px' />　
			<img src="interface.php?type=code" onclick="ChangeCode(this)" id='MainCounty_CodeImg' alt="点击" style='height:40px' align='top' />
		</div>
	</div-->

	<div style='text-align:center'>
		<button id='MainCounty_Sub'>修改</button>
	</div>
</div>

<script>


//同步更新开通城市到upyun
$('#openCitySameUpyun').click(function(){
	Notice('处理中......');
	AjaxAdmin({type:'openCitySameUpyun'},function(res){
		Notice();	//关闭提示框
		var tmp = _checkJsonFormat(res);
		if(tmp.stat == 'ok'){
			A('操作成功！');			
		}else{
			A('操作异常！');
		}
	});
});


//状态维持
if(sessionStorage.admin_cityOpenType){
	$('#MainCounty_CityOpenStat').val(sessionStorage.admin_cityOpenType);
}


//获取城市信息
getCityInfoFull(function(cityList){
	//解析城市到下拉框
	City_ParseCity(cityList,GetOpenType(),MainCounty_Province,MainCounty_City,MainCounty_County,function(){

		MainCounty_ViewDbInfoForCounty(MainCounty_County,MainCounty_DbHost,MainCounty_DbName);	//解析库址

	});

	$('#MainCounty_CityOpenStat').change(function(){	//状态切换
		sessionStorage.admin_cityOpenType = GetOpenType();	//缓存开通城市类型
		location.reload();
	});
});	


//获取当前选择的开通状态
function GetOpenType(){
	return $('#MainCounty_CityOpenStat').find('option:selected').val();
}





//修改城市库址，库名
$('#MainCounty_Sub').click(function(){
	// if(!_confirm()){
	// 	return;
	// }
	var Host = ChangeChar($('#MainCounty_DbHost').val().trim());
	var Name = ChangeChar($('#MainCounty_DbName').val().trim());
	if($('#MainCounty_County').html().length < 1){
		if(!CountyCode){
			A('没有选择城市！');
			return;
		}
	}
	var CountyCode = $('#MainCounty_County').find('option:selected').val().split(',')[0];
	if(Host == sessionStorage.MainCounty_DbHost && Name == sessionStorage.MainCounty_DbName){
		A('数据没有变动 ！');return;
	}

	//var VCode = $('#MainCounty_VCode').val().trim();
	//Field_Check(/^\w{4}$/,Code,'验证码不正确！');		//检测库名

	if(Host && !ChacekIpFormart(Host)){
		A('iP地址不合法！');return;							//检测ip
	}
	Field_Check(/^$|^[a-z]\w{1,29}$/,Name,'库名不合法！');		//检测库名

	var data = {
		type:'updateCityInfo',
		host:Host,
		name:Name,
		//code:VCode,
		county_code:CountyCode
	};
	AjaxAdmin(data,function(res){
		var tmp = _checkJsonFormat(res);
		switch(tmp.stat){
			case 'ok':
				//sessionStorage.cityList = '';//重置开城市缓存
				A('修改成功!');
				location.reload();
				break;
			case 'err2':
				A('修改失败');
				break;
		}
	});
});



</script>
